﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
/// <summary>
/// Summary description for clsPageDAL
/// </summary>
public class clsPageDAL
{
    InstantNaukriDataContextDataContext objInstantNaukriDataContextDataContext = new InstantNaukriDataContextDataContext();
    public clsPageDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public List<IN_TB_PAGE_MST> GetAllPage()
    {
        try
        {
            List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
            objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                 select obj).ToList();
            return objIN_TB_PAGE_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_PAGE_MST GetPageById(int ID)
    {
        try
        {
            IN_TB_PAGE_MST objIN_TB_PAGE_MST = new IN_TB_PAGE_MST();
            objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                 where obj.ID == ID
                                 select obj).SingleOrDefault();
            return objIN_TB_PAGE_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public int SavePage(IN_TB_PAGE_MST objIN_TB_PAGE_MST)
    {
        try
        {
            IN_TB_PAGE_MST objIN_TB_PAGE_MSTD = new IN_TB_PAGE_MST();
            objIN_TB_PAGE_MSTD = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                  where obj.ID == objIN_TB_PAGE_MST.ID
                                  select obj).SingleOrDefault();
            if (objIN_TB_PAGE_MSTD != null)
            {
                objIN_TB_PAGE_MSTD.ID = objIN_TB_PAGE_MST.ID;
                objIN_TB_PAGE_MSTD.PAGE_URL = objIN_TB_PAGE_MST.PAGE_URL;
                objIN_TB_PAGE_MSTD.PAGE_NAME = objIN_TB_PAGE_MST.PAGE_NAME;
                objIN_TB_PAGE_MSTD.CREATED_BY = objIN_TB_PAGE_MST.CREATED_BY;
                objIN_TB_PAGE_MSTD.CREATED_ON = objIN_TB_PAGE_MST.CREATED_ON;
                objIN_TB_PAGE_MSTD.MODIFIED_BY = objIN_TB_PAGE_MST.MODIFIED_BY;
                objIN_TB_PAGE_MSTD.MODIFIED_ON = objIN_TB_PAGE_MST.MODIFIED_ON;
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_PAGE_MSTD.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs.InsertOnSubmit(objIN_TB_PAGE_MST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_PAGE_MST.ID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<IN_TB_PAGE_MST> GetPageByUserId(int UserID)
    {
        try
        {
            List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
            objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                 join objAccess in objInstantNaukriDataContextDataContext.IN_TB_USER_ACCESS_DENIEDs on obj.ID equals objAccess.PAGE_ID
                                 where objAccess.USERID == UserID
                                 select obj).ToList();
            return objIN_TB_PAGE_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<IN_TB_PAGE_MST> GetPageByRoleId(int RoleId)
    {
        try
        {
            List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
            objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                 join objRolePage in objInstantNaukriDataContextDataContext.IN_TB_ROLE_PAGEs on obj.ID equals objRolePage.PAGE_ID
                                 where (objRolePage.ROLEID == RoleId)
                                 select obj).ToList();
            return objIN_TB_PAGE_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<IN_TB_PAGE_MST> GetPageNotAssignedByRoleId(int RoleId)
    {
        try
        {
            List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
            objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                 where !(from objRolePage in objInstantNaukriDataContextDataContext.IN_TB_ROLE_PAGEs
                                         join objPage in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs on objRolePage.PAGE_ID equals objPage.ID
                                         where objRolePage.ROLEID == RoleId
                                         select objPage.ID
           ).Contains(obj.ID)
                                 select obj
           ).ToList();

            return objIN_TB_PAGE_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<clsRolePageBo> GetRolePageByRoleId(int RoleId)
    {
        try
        {
            List<clsRolePageBo> objIN_TB_PAGE_MST = new List<clsRolePageBo>();
            objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                 join objRolePage in objInstantNaukriDataContextDataContext.IN_TB_ROLE_PAGEs on obj.ID equals objRolePage.PAGE_ID
                                 where (objRolePage.ROLEID == RoleId)
                                 select new clsRolePageBo
                                 {
                                     ROLE_PAGE_ID = objRolePage.ID,
                                     PAGE_NAME = obj.PAGE_NAME
                                 }).ToList();
            return objIN_TB_PAGE_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    //public List<IN_TB_PAGE_MST> GetPageNotAssignedByRoleId(int RoleId)
    //{
    //    try
    //    {
    //        List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
    //        objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
    //                             join objRolePage in objInstantNaukriDataContextDataContext.IN_TB_ROLE_PAGEs on obj.ID equals objRolePage.PAGE_ID
    //                             where (objRolePage.ROLEID != RoleId)
    //                             select obj).ToList();
    //        return objIN_TB_PAGE_MST;
    //    }
    //    catch (Exception)
    //    {

    //        throw;
    //    }
    //}

    public List<IN_TB_PAGE_MST> GetPageByRoleIdLeft(int RoleId)
    {
        try
        {
            List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
            objIN_TB_PAGE_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_PAGE_MSTs
                                 join objRolePage in objInstantNaukriDataContextDataContext.IN_TB_ROLE_PAGEs on obj.ID equals objRolePage.PAGE_ID
                                 where (objRolePage.ROLEID == RoleId)
                                 select obj).ToList();
            return objIN_TB_PAGE_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }
}
